/************************************************************************
 * IMAGEENTITY class
 * by Marc-Henri Vuillaume
 *************************************************************************
 ** * * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 **********************************************************************/

package mhv.fr.sprite;

import java.awt.Graphics2D;
import java.awt.Image;
import mhv.fr.utils.RessourcesManager;

/**
 * ImageEntity is an image container class.
 * @author Marc-Henri
 */
public class ImageEntity {
    /**
     * The graphics surface using for drawing
     */
    private Graphics2D g2d;
    
    /**
     * The image
     */
    private Image image;
    
    /**
     * Load the image.
     * @param filename
     */
    public void load(String filename) {
        RessourcesManager rs = RessourcesManager.getInstance();
        image = rs.LoadImage (filename);
    }

    /**
     * Getter method.
     * @return Graphics2D
     */
    public Graphics2D getGraphics() {
        return g2d;
    }

    /**
     * Setter method
     * @param g2d
     */
    public void setGraphics(Graphics2D g2d) {
        this.g2d = g2d;
    }

    /**
     * Getter method.
     * @return Image
     */
    public Image getImage() {
        return image;
    }

    /**
     * Setter method
     * @param image
     */
    public void setImage(Image image) {
        this.image = image;
    }
    
    /**
     * draw this image into the drawng surface.
     */
    public void draw() {
        draw(g2d);
    }
    
    /**
     * draw this Sprite into the drawng surface G.
     * @param g 
     */
    public void draw(Graphics2D g) {
        g.drawImage(image, -image.getWidth(null)/2, -image.getHeight(null)/2, null);
    }
    
    /**
     * return the image width.
     * @return int
     */
    public int width() {
        if (image != null)
            return image.getWidth(null);
        else
            return 0;
    }
    
    /**
     * return the image height.
     * @return int
     */
    public int height() {
        if (image != null)
            return image.getHeight(null);
        else
            return 0;
    }

    /**
     * Construct and initilize ImageEntity.
     */
    public ImageEntity() {
        g2d = null;
        image = null;
    }
    
    
    
    

}
